/**
 * 获取浏览器属性
 * @returns { string } name 浏览器名称
 * @returns { string } version 浏览器版本
 * **/
export const getBrowserInfo = () => {
    const userAgent = window.navigator.userAgent;
    let browserName: string = '',
        browserVersion: string = '';

    if (/Chrome/i.test(userAgent)) {
        browserName = 'Chrome';
    } else if (/Firefox/i.test(userAgent)) {
        browserName = 'Firefox';
    } else if (/Safari/i.test(userAgent)) {
        browserName = 'Safari';
    } else if (/Opera|OPR/i.test(userAgent)) {
        browserName = 'Opera';
    } else if (/Edge/i.test(userAgent)) {
        browserName = 'Edge';
    } else if (/MSIE/i.test(userAgent) || /Trident/i.test(userAgent)) {
        browserName = 'IE';
    } else {
        browserName = 'Unknown';
    }

    const versionMatch = userAgent.match(
        /(Chrome|Firefox|Safari|Opera|Edge|IE)\/?\s*(\.?\d+(\.\d+)*)/i
    );

    if (versionMatch && versionMatch.length >= 3) {
        browserVersion = versionMatch[2];
    } else {
        browserVersion = 'Unknown';
    }
    return {
        name: browserName,
        version: browserVersion
    };
};
